<template>
	<!-- 财务管理 -->
	<div class="app-container">
		<!-- 使用搜索组件 -->
		<searchOption id="searchForm" ref="searchUnit" type="outSideTask" :total="total" :status="queryParams.status"
			@searchList="parentSearchList"></searchOption>
		<vxe-table border ref="xTable" show-overflow :data="infoList" :column-config="{ resizable: false }"
			:edit-config="{ trigger: 'click', mode: 'cell' }" @scroll="srcollFn" :height="autoTableHeight">
			<vxe-colgroup fixed="left">
				<vxe-column field="contractType" title="合同类别" width="70">
					<template #default="{ row }">
						<dict-tag style="display: inline;" :options="dict.type.contract_type" :value="row.contractType" />
					</template>
				</vxe-column>

				<vxe-column field="useName" title="办理人" width="60"
					:visible="(queryParams.pageType == '1' || queryParams.pageType == '2') && userNameFlag">
					<template #default="{ row }">
						<span>{{ row.userName }}</span>
					</template>
				</vxe-column>

				<vxe-column field="customManager" title="销售经理" width="70">
					<template #default="{ row }">
						<span>{{ row.customManager }}</span>
					</template>
				</vxe-column>

				<vxe-column field="customName" title="公司名称" width="230">
					<template #default="{ row }">
						<span>{{ row.customName }}</span>
					</template>
				</vxe-column>

				<vxe-column field="legalName" title="法人姓名" width="70">
					<template #default="{ row }">
						<span>{{ row.legalName }}</span>
					</template>
				</vxe-column>

				<vxe-column field="callName" title="客户姓名" width="70">
					<template #default="{ row }">
						<span>{{ row.callName }}</span>
					</template>
				</vxe-column>

				<vxe-column field="callPhone" title="客户电话" width="90" show-overflow="title">
					<template #default="{ row }">
						<span>{{ row.callPhone }}</span>
					</template>
				</vxe-column>
			</vxe-colgroup>

			<!-- <vxe-column field="status" title="客户状态" width="90">
				<template #default="{ row }">
					<span>{{ formatStatus(row.status) }}</span>
				</template>
			</vxe-column> -->

			<vxe-column field="gmtCreate" title="成交时间" width="120">
				<template #default="{ row }">
					<span>{{ row.gmtCreate }}</span>
				</template>
			</vxe-column>

			<!-- <vxe-column title="操作" width="90" :visible="queryParams.pageType == 0">
				<template #default="{ row }">
					<el-button size="mini" type="text" icon="iconfont ali-iconchakan"
						@click="checkDetails(row.customId)">查看详情</el-button>
				</template>
			</vxe-column> -->
			<vxe-column field="legalPersonNumber" title="法人身份证" width="120" show-overflow="title">
				<template #default="{ row }">
					<span>{{ formatLegalPersonNumber(row.legalPersonNumber) }}</span>
				</template>
			</vxe-column>

			<vxe-column field="openName" title="开户人" width="70">
				<template #edit="{ row }">
					<vxe-input v-model="row.openName" type="text" placeholder="请输入开户人" @blur="nameChangeEvent({ row })">
					</vxe-input>
				</template>
			</vxe-column>

			<vxe-column field="customNumber" title="纳税人识别号" width="120">
				<template #edit="{ row }">
					<vxe-input v-model="row.customNumber" type="text" placeholder="请输入纳税人识别号" @blur="nameChangeEvent({ row })">
					</vxe-input>
				</template>
			</vxe-column>

			<vxe-column field="taxpayerQualification" title="纳税人资格" width="120">
				<template #edit="{ row }">
					<vxe-input v-model="row.taxpayerQualification" type="text" placeholder="请输入纳税人资格"
						v-if="row.contractType == 1 || row.contractType == 2" @blur="nameChangeEvent({ row })">
					</vxe-input>
					<span v-else>111</span>
				</template>
			</vxe-column> -->

			<vxe-column field="companyDate" title="公司成立日期" width="90">
				<template #edit="{ row }">
					<span>{{ row.companyDate }}</span>
				</template>
			</vxe-column>

			<vxe-column field="stopAccountDate" title="停用账期日期" width="90">
				<template #edit="{ row }">
					<span>{{ row.stopAccountDate }}</span>
				</template>
			</vxe-column>

			<vxe-column field="stopDate" title="停用时间" width="90">
				<template #edit="{ row }">
					<span>{{ row.stopDate }}</span>
				</template>
			</vxe-column>

			<vxe-column field="stopRemark" title="停用原因" width="90">
				<template #edit="{ row }">
					<span>{{ row.stopRemark }}</span>
				</template>
			</vxe-column>

			<vxe-column field="adressDetail" title="地址详情" width="150">
				<template #edit="{ row }">
					<vxe-input v-model="row.adressDetail" type="text" placeholder="请输入地址详情" @blur="nameChangeEvent({ row })">
					</vxe-input>
				</template>
			</vxe-column>

			<vxe-column field="taxPassword" title="税务密码" width="120">
				<template #edit="{ row }">
					<vxe-input v-model="row.taxPassword" type="text" placeholder="请输入税务密码" @blur="nameChangeEvent({ row })">
					</vxe-input>
				</template>
			</vxe-column>

			<vxe-column field="personPassword" title="个税密码" width="120">
				<template #edit="{ row }">
					<vxe-input v-model="row.personPassword" type="text" placeholder="请输入个税密码" @blur="nameChangeEvent({ row })">
					</vxe-input>
				</template>
			</vxe-column>

			<vxe-column field="accountBank" title="开户行名称" width="120">
				<template #edit="{ row }">
					<vxe-input v-model="row.accountBank" type="text" placeholder="请输入开户行名称" @blur="nameChangeEvent({ row })">
					</vxe-input>
				</template>
			</vxe-column>

			<vxe-column field="bankManagerPhone" title="开户行客户经理电话" width="180">
				<template #edit="{ row }">
					<vxe-input v-model="row.bankManagerPhone" type="text" placeholder="请输入开户行客户经理电话"
						@blur="nameChangeEvent({ row })"></vxe-input>
				</template>
			</vxe-column>

			<vxe-column field="madeSignCompanyName" title="刻章公司名称" width="180">
				<template #edit="{ row }">
					<vxe-input v-model="row.madeSignCompanyName" type="text" placeholder="请输入刻章公司名称"
						@blur="nameChangeEvent({ row })"></vxe-input>
				</template>
			</vxe-column>

			<vxe-column v-for="item in uploadImgItem" :key="item.dictValue" :title="item.dictLabel"
				:width="item.dictLabel.length * 10 + 40" align="center">
				<template #default="{ row }">
					<el-button size="mini" type="text" style="color: #333;" v-if="imgPath(row, item.dictValue)"
						@click="uploadTableImg(row, item.dictValue)">客户未涉及</el-button>
					<el-button v-else size="mini" type="text" @click="uploadTableImg(row, item.dictValue)">
						<el-popover placement="bottom" width="720" v-if="contractItem(row, item.dictValue)" trigger="hover"
							@show="popoverFc({ row }, item.dictValue)">
							<span slot="reference" @click.stop="uploadTableImg(row, item.dictValue, true)">
								<span class="iconfont ali-iconchakan" style="font-size: 15px;color: #13ce66;"></span>
								<span style="color: #13ce66;vertical-align:text-top;margin-left:3px;">查看</span>
							</span>
							<img v-if="imageSrc !== ''" :src="imageSrc" width="700px" />
							<el-button v-show="imageSrc !== ''" size="mini" type="primary" style="float: right;margin-top: 5px;"
								@click="downLoadImg()">下载图片</el-button>
						</el-popover>
						<span v-else-if="queryParams.status != 5" @click.stop="uploadTableImg(row, item.dictValue, false)">
							<span>上传图片</span>
							<span style="margin-left: 3px" @click.stop="noNeedToUpload({ row }, item.dictValue)"> 无 </span>
						</span>
					</el-button>
				</template>
			</vxe-column>

			<vxe-column field="accumulationFundTime" title="公积金开启时间" width="100">
				<template #edit="{ row }">
					<vxe-input v-model="row.accumulationFundTime" type="date" placeholder="请选择日期" transfer
						@change="nameChangeEvent({ row })"></vxe-input>
				</template>
			</vxe-column>

			<vxe-column field="accumulationFundTimeEnd" title="公积金结束时间" width="100">
				<template #edit="{ row }">
					<vxe-input v-model="row.accumulationFundTimeEnd" type="date" placeholder="请选择日期" transfer
						@change="nameChangeEvent({ row })"></vxe-input>
				</template>
			</vxe-column>

			<vxe-column field="socialSecurityTime" title="社保开启时间" width="100">
				<template #edit="{ row }">
					<vxe-input v-model="row.socialSecurityTime" type="date" placeholder="请选择日期" transfer
						@change="nameChangeEvent({ row })"></vxe-input>
				</template>
			</vxe-column>

			<vxe-column field="socialSecurityTimeEnd" title="社保结束时间" width="100">
				<template #edit="{ row }">
					<vxe-input v-model="row.socialSecurityTimeEnd" type="date" placeholder="请选择日期" transfer
						@change="nameChangeEvent({ row })"></vxe-input>
				</template>
			</vxe-column>
			<vxe-colgroup fixed="right">
				<vxe-column title="操作" width="120" v-if="queryParams.pageType == 1">
					<template #default="{ row }">
						<!-- <el-button size="mini" type="text" @click="createContract(row)">生成合同</el-button> -->
						<el-button size="mini" type="text" @click="insideTaskBtn(row)"
							v-if="row.contractTaskUserId == null">分配任务</el-button>
						<el-button size="mini" type="text" @click="openHistoryContract(row)">历史合同</el-button>
					</template>
				</vxe-column>
				<vxe-column title="操作" width="120" v-if="queryParams.pageType == 2">
					<template #default="{ row }">
						<el-button size="mini" type="text" @click="createContract(row)">生成合同</el-button>
						<el-button size="mini" type="text" @click="openHistoryContract(row)">历史合同</el-button>
					</template>
				</vxe-column>
			</vxe-colgroup>
		</vxe-table>
		<!-- 图片上传 -->
		<el-dialog :visible.sync="uploadImgVis" :modal="true" width="35%" title="图片上传" append-to-body>
			<div v-if="imageSrc !== ''">
				<img :src="imageSrc" style="width: 100%;" height="30%" />
				<div style="line-height: 50px">
					提示：可通过下方上传控件进行重新上传该图片
				</div>
			</div>
			<el-upload class="upload-demo" drag :action="uploadImgUrl" :headers="headers" :on-success="imgSuccess"
				:data="{ contractId: this.contractId, customId: this.customId, contractType: this.contractType, businessId: this.businessId }"
				accept=".jpeg,.jpg,.png" ref="uploadImg">
				<i class="el-icon-upload"></i>
				<div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
				<div class="el-upload__tip" slot="tip">
					<span>只能上传jpg/png文件</span>
					<el-button v-show="imageSrc !== ''" size="mini" type="primary" style="float: right;"
						@click="downLoadImg()">下载图片</el-button>
				</div>
			</el-upload>
		</el-dialog>
		<!-- 生成续费合同 -->
		<el-dialog title="生成合同" :visible.sync="openContract" width="60%" append-to-body :close-on-click-modal="false">
			<contract-dia ref="contractDiaRef" @closeDialog="cancelContract" :rowObj="rowObj"></contract-dia>
		</el-dialog>
		<!-- 历史合同 -->
		<el-dialog title="历史合同" :visible.sync="openHistoryContractVis" width="60%" append-to-body>
			<history-contract ref="historyContractRef"></history-contract>
		</el-dialog>
		<!-- 分配任务 -->
		<el-dialog ref="insideTaskRef" :visible.sync="insideTaskVis" :modal="true" width="50%" height="50%" title="任务分配"
			append-to-body>
			<el-row :gutter="15">
				<el-form ref="elForm" :model="insideTaskForm" size="medium" label-width="100px">
					<el-col :span="24">
						<el-form-item label="选择人的名称" prop="handleName">
							<el-select v-model="insideTaskForm.handleName" placeholder="请选择选择人的名称" style="width: 100%">
								<el-option v-for="item in internalStaff" :key="item.userName" :value="item.userId"
									:label="item.nickName">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>

			<div slot="footer">
				<el-button @click="insideTaskFormClose"> 取消 </el-button>
				<el-button type="primary" @click="insideTaskFormConfirm">
					确定
				</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
import {
	updateInfo,
	loadImage,
	listForFinance,
	contractCustomList,
	loadContractImage,
	recordDetail,
	contractTaskUser
} from "@/api/system/info";
import { askStamp } from "@/api/contract/info";
import request from '@/utils/request';
import ContractDia from "@/components/ContractDia";
import historyContract from "@/components/historyContract";
import { updateRemark, listRemark } from "@/api/system/remark";
import { pcaTextArr } from "element-china-area-data";
import second from "@/components/Crontab/second.vue";
import { getToken } from "@/utils/auth";
import { listUser } from "@/api/system/user";
import { allocatedUserList } from "@/api/system/role";

import { addTask } from "@/api/outsideTask/outSidetask";
import searchOption from "@/components/searchOption";

export default {
	components: {
		searchOption,
		ContractDia,
		historyContract
	},
	name: "Info",
	dicts: ["contract_type"],//"status_custom", "contract_step_value",
	data() {
		return {
			userNameFlag: false,
			insideTaskVis: false,
			downLoadImgObj: {},
			popViewImgFlag: true,
			requeryFlag: true,
			pcaTextArr,
			detailObj: {
				detailListModal: false,
				detailList: [],
				customId: null
			},
			insideTaskForm: {
				customId: null,
				contractId: null,
				handleContent: null,
				handleName: null,
				contractTaskId: null,
			},
			contractType: null,
			uploadImgItem: [],
			autoTableHeight: 750,
			selectedOptions: [],
			remarkId: "",
			internalStaff: [],
			formRemark: {},
			openRecord: false,
			loading: true,
			rowObj: {},//生成合同所需的行数据
			openContract: false,//生成合同的弹层
			// 选中数组
			ids: [],
			// 总条数
			total: 0,
			// 客户信息表格数据
			infoList: [],
			// 弹出层标题
			title: "",
			// 是否显示弹出层
			open: false,
			businessId: null,
			// 查询参数
			queryParams: {
				pageNum: 1,
				pageSize: 30,
				customName: null,
				legalName: null,
				customNumber: null,
				province: null,
				callPhone: null,
				callName: null,
				customManager: null,
				gmtCreate: null,
				status: 0,
			},
			queryEmp: {
				pageNum: 1,
				pageSize: 30,
				deptId: 200,
			},
			dateRange: [],
			breadList: [], //初始化
			openHistoryContractVis: false,
			uploadImgUrl:
				process.env.VUE_APP_BASE_API + "/custom/info/uploadContractImage",
			headers: {
				Authorization: "Bearer " + getToken(),
			},

			uploadImgVis: false,
			viewImgVis: false,
			imageSrc: "",
			customId: "",
			uploadKey: "",
			popoverVis: false,
			hoverId: "",
			contractId: null,
		};
	},
	watch: {
		// 监听路由对象中的变化
		'$route': {
			handler: function (from, to) {
				// 当路由发生变化时会调用这个函数
				this.infoList = [];
				this.queryParams.pageNum = 1;
				this.queryParams.pageSize = 30;
				this.queryParams.customName = null;
				this.queryParams.callPhone = null;
				this.queryParams.callName = null;
				this.queryParams.customManager = null;
				this.queryParams.pageType = from.query.pageType;
				this.queryParams.contractType = from.query.contractType;
				this.getList();
				//动态设置部分列头
				let columnId = null;
				let uploadCol = this.$store.state.user.contractTypeUpload;
				uploadCol.forEach(element => {
					if (element.dictValue == from.query.dictValue) {
						columnId = element.remark.split(",");
					}
				});
				let contractUploadItems = this.$store.state.user.contractUploadItems;
				contractUploadItems.forEach(element => {
					if (columnId && columnId.includes(element.dictValue)) {
						this.uploadImgItem.push(element);
					}
				});
			},
			// 如果需要在路由变化时立即响应，可以设置immediate为true
			immediate: true
		}
	},
	created() {
		// 检查登录账户是否为销售主管，如果不是则不显示导入导出
		let roles = this.$store.state.user.roles;
		if (roles.length > 0) {
			roles.forEach(item => {
				if (item == 'topManager' || item == 'admin' || item == 'admin') {
					this.userNameFlag = true;
					return
				}
			});
		}
	},
	computed: {
		second() {
			return second;
		},
		// 显示上传图片或查看图片
		contractItem(row, id) {
			return function (row, id) {
				let allItem = row.contractItem;
				if (allItem == null || allItem == '') {
					return false
				} else {
					let itemArray = allItem.split(";");
					let ids = []
					for (let i = 0; i < itemArray.length; i++) {
						ids.push(itemArray[i].split(',')[0])
					}
					if (ids.includes(id)) {
						return true
					} else {
						return false
					}
				}
			}
		},
		// 上传图片项是否显示“客户未涉及”
		imgPath(row, id) {
			return function (row, id) {
				let allItem = row.contractItem;
				if (allItem == null || allItem == '') {
					return false
				} else {
					let itemArray = allItem.split(";");
					for (let i = 0; i < itemArray.length; i++) {
						let key = itemArray[i].split(',')[0];
						let value = itemArray[i].split(',')[1];
						if (id == key) {
							if (value == '-1') {
								return true
							} else {
								return false
							}
						}
					}
				}
			}
		}
	},
	mounted() {
		this.$nextTick(() => {
			// 视口高度 - 列表上方的元素高度
			let allHeight = window.innerHeight;
			let element = [
				document.getElementById('navbar'),
				document.getElementById('searchForm'),
				document.getElementById('tags-view-container'),
			]
			let domHeight = element.map(item => item.offsetHeight)
			// let tableHeight = allHeight - 50 - 34 - 50 - 36;
			let tableHeight = allHeight - 40 - domHeight[0] - domHeight[1] - domHeight[2];
			this.autoTableHeight = tableHeight;
		})
	},
	methods: {
		// 搜索子组件触发搜索
		parentSearchList(data) {
			this.queryParams.pageNum = data.pageNum;
			this.queryParams.pageSize = data.pageSize;
			this.queryParams.callName = data.callName;
			this.queryParams.callPhone = data.callPhone;
			this.queryParams.customName = data.customName;
			this.queryParams.customManager = data.customManager;
			this.handleQuery();
		},
		// status格式化
		formatStatus(value) {
			if (value == "1") {
				return "存续";
			}
			if (value == "2") {
				return "注销";
			}
			if (value == "3") {
				return "转走";
			}
			if (value == "4") {
				return "欠费停账";
			}
			return "未知";
		},
		// 查询 会计做账人员
		listUser(num) {
			allocatedUserList({
				pageNum: 1,
				pageSize: 999,
				roleId: num,
				userName: undefined,
				phonenumber: undefined,
			}).then((response) => {
				this.internalStaff = response.rows;
			});
		},
		// 身份证号加密
		formatLegalPersonNumber(value) {
			if (value == null || value == '') {
				return ''
			} else {
				let idCard = value.substring(0, 6) + '********' + value.substring(14, 18);
				return idCard;
			}
		},
		// 手机号加密
		formatCallPhone(value) {
			if (value == null || value == '') {
				return ''
			} else {
				let phone = value.substring(0, 3) + '****' + value.substring(7, 11);
				return phone;
			}
		},
		/** 搜索按钮操作 */
		handleQuery() {
			this.queryParams.pageNum = 1;
			this.getList();
		},
		/** 查询客户信息列表 */
		getList() {
			this.loading = true;
			this.queryParams.pageNum = 1;
			if (this.queryParams.pageType == 0) {
				contractCustomList(this.queryParams).then((response) => {// 客户档案数据
					this.infoList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			} else if (this.queryParams.pageType == 1) { // 财务模块的客户信息
				listForFinance(this.queryParams).then((response) => {
					this.infoList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			} else if (this.queryParams.pageType == 2) {// 做账会计数据
				listForFinance(this.queryParams).then((response) => {
					this.infoList = response.rows;
					this.total = response.total;
					this.loading = false;
				});

			}
		},
		// 取消按钮
		cancel() {
			this.open = false;
		},
		// 查看详情
		checkDetails(customId) {
			this.detailObj.detailList = [];
			let pageNumCopy = this.queryParams.pageNum;
			this.queryParams.pageNum = 1;
			this.detailObj.customId = customId;
			this.queryParams.customId = customId;
			contractCustomList(this.queryParams).then((response) => {
				delete this.queryParams.customId;
				this.queryParams.pageNum = pageNumCopy;
				this.detailObj.detailListModal = true;
				this.detailObj.detailList = response.rows;
			}).catch((err) => {
				// this.$modal.msgError('加载失败！');
			});
		},
		//分配任务
		insideTaskBtn(row) {
			this.insideTaskVis = true;
			// this.insideTaskForm.customId = row.customId;
			// this.insideTaskForm.taskId = row.taskId;
			this.insideTaskForm.contractId = row.contractId;
			this.insideTaskForm.contractTaskId = row.id;
			this.listUser(109);
		},
		// 确认分配任务
		insideTaskFormConfirm() {
			if (this.insideTaskForm.handleName == null) {
				this.$modal.msgError("请选择分配人员");
				return
			}
			let params = {
				userId: this.insideTaskForm.handleName,
				contractId: this.insideTaskForm.contractId,
				contractTaskId: this.insideTaskForm.contractTaskId,
			};
			console.log(params);
			contractTaskUser(params).then((response) => {
				if (response.code === 200) {
					this.insideTaskFormClose();
					this.$modal.msgSuccess("派单成功");
					this.getList();
				}
			});
		},
		// 表单关闭
		insideTaskFormClose() {
			this.insideTaskForm = {
				taskId: null,
				customId: null,
				contractId: null,
				handleContent: null,
				handleName: null,
				contractTaskId: null,
			};
			this.insideTaskVis = false;
		},
		// 滚动加载
		srcollFn(e) {
			let circulateNum = this.total / 30;
			let bottomOffset = e.scrollHeight - e.scrollTop - e.bodyHeight;
			if (bottomOffset < 50 && this.queryParams.pageNum < circulateNum) {
				if (this.requeryFlag) {
					this.requeryFlag = false;
					this.loading = true;
					this.queryParams.pageNum++;
					const h = this.$createElement;
					if (this.queryParams.pageType == 0) {
						contractCustomList(this.queryParams).then((response) => {
							this.infoList = [...this.infoList, ...response.rows];
							// this.total = response.total;
							this.loading = false;
							this.requeryFlag = true;
						});
					} else {
						listForFinance(this.queryParams).then((response) => {
							this.infoList = [...this.infoList, ...response.rows];
							// this.total = response.total;
							this.loading = false;
							this.requeryFlag = true;
						});
					}
				}
			}
		},
		//查看图片  查找文件名
		popoverFc(row, key) {
			if (!this.popViewImgFlag) {
				return
			}
			this.popViewImgFlag = false;
			this.downLoadImgObj = row;
			this.downLoadImgObj.key = key;
			let contractItem = row.row.contractItem;
			if (contractItem == '' || contractItem == null) {
				return
			} else {
				let itemArray = contractItem.split(';');
				for (let i = 0; i < itemArray.length; i++) {
					if (itemArray[i].split(',')[0] == key) {
						this.uploadKey = itemArray[i].split(',')[1];
						break;
					}
				}
				this.successActions();
			}
		},
		// 申请修改资料
		applicationForModification(row) {
			console.log(row);
			this.$modal.confirm('若需要更新上传材料，需先提前申请，确认申请吗？').then(() => {
				let data = {};
				data.type = 3;// 类型写死
				data.contractId = row.contractId;
				data.customId = row.customId;
				data.callName = row.callName;
				data.callPhone = row.callPhone;
				data.customName = row.customName;
				// data.sealStatus = row.sealStatus;
				data.auditImageStatus = row.auditImageStatus;
				data.remark = '';
				data.contractCode = row.contractCode;
				data.contractType = row.contractType;
				data.customManager = row.customManager;
				data.contractAmount = row.contractAmount;
				data.entrustCycleEnd = row.entrustCycleEnd;
				data.entrustCycleStrat = row.entrustCycleStrat;
				data.paidAmount = row.paidAmount == null ? 0 : row.paidAmount;
				data.unPaidAmount = row.unPaidAmount == null ? row.contractAmount : row.unPaidAmount;
				console.log(data);
				return askStamp(data);
			}).then(() => {
				// 本地更新数据
				this.$modal.msgSuccess('操作成功，等待审批！');
				row.auditImageStatus = 3;
				this.$refs.xTable.updateData(row)
			}).catch(() => { });
		},
		// 打开上传弹窗
		uploadTableImg(row, key, boolean) {
			if (this.queryParams.status == 5) {
				return
			}
			// 财务信息--任务列表更新图片时，先提交申请，申请通过后可更新图片
			if (this.queryParams.pageType == 2) {
				// 0未审核  1审核通过  2拒绝  3申请中
				if (row.auditImageStatus == 0) {
					this.applicationForModification(row);
					return
				} else if (row.auditImageStatus == 2) {
					this.$modal.msgError('申请已被拒绝，无法更新材料！')
					return
				} else if (row.auditImageStatus == 3) {
					this.$modal.msgSuccess('正在申请中！')
					return
				}
			}
			if (!boolean) {
				this.imageSrc = '';
			}
			this.downLoadImgObj = row;
			this.downLoadImgObj.key = key;

			this.uploadImgVis = true;
			this.uploadKey = key;
			this.customId = row.customId;
			this.contractType = row.contractType;
			this.contractId = row.contractId;
			this.businessId = key;
			this.$refs.uploadImg.clearFiles();
			// this.successAction();
		},
		// 图片上传项，不需要上传
		noNeedToUpload(row, key) {
			// 财务信息--任务列表更新图片时，先提交申请，申请通过后可更新图片
			if (this.queryParams.pageType == 2) {
				// 0未审核  1审核通过  2拒绝  3申请中
				if (row.auditImageStatus == 0) {
					this.applicationForModification(row);
					return
				} else if (row.auditImageStatus == 2) {
					this.$modal.msgError('申请已被拒绝，无法更新材料！')
					return
				} else if (row.auditImageStatus == 3) {
					this.$modal.msgSuccess('正在申请中！')
					return
				}
			}
			let that = this;
			this.$modal.confirm('确认客户不涉及此上传项吗？').then(() => {
				request({
					url: "/custom/info/uploadContractImageNULL",
					headers: {
						'Authorization': "Bearer " + getToken()
					},
					method: 'post',
					data: {
						businessId: key,
						customId: row.row.customId,
						contractId: row.row.contractId,
						contractType: row.row.contractType,
					}
				}).then(response => {
					this.successActions(true)
					// 本地更新数据
					// let xTable = this.$refs.xTable;
					// let index = xTable.getRowIndex(row.row)
					// let rowData = this.infoList[index];
					// let contractItem = rowData.contractItem + (rowData.contractItem == '' ? `${key}:-1` : `;${key}:-1`)
					// let oldInfoList = this.infoList;
					// oldInfoList[index].contractItem = contractItem;
					// this.$set(this.infoList[index], 'contractItem', contractItem);
					// xTable.updateData(rowData)
				})
			})
		},
		//上传图片成功
		successAction() {
			this.getList();
			this.imageSrc = "";
			loadImage(this.customId, this.uploadKey).then((response) => {
				if (response.type === "image/jpg") {
					const blobData = {};
					blobData.type = "application/image;chartset=UTF-8";
					this.imageSrc = window.URL.createObjectURL(
						new Blob([response], blobData)
					);
				}
			});
		},
		// 图片上传成功后的回调
		imgSuccess() {
			this.successActions(true)
		},
		//请求图片  预览
		successActions(flag) {
			if (flag) {
				this.getList();
				// this.checkDetails(this.detailObj.customId)
				return
			}
			this.imageSrc = "";
			loadContractImage(this.uploadKey).then((response) => {
				if (response.type === "image/jpg") {
					const blobData = {};
					blobData.type = "application/image;chartset=UTF-8";
					this.imageSrc = window.URL.createObjectURL(
						new Blob([response], blobData)
					);
				}
				this.popViewImgFlag = true;
			}).catch(() => {
				this.imageSrc = "";
				this.popViewImgFlag = true;
			});
		},
		//生成合同
		createContract(row) {
			this.openContract = true;
			this.rowObj = row;
			this.rowObj.id = row.customId;
			this.rowObj.isNew = true;
			// 第一次生成合同的标识
			this.rowObj.firstGeneration = true;
			this.rowId = row.id;
			this.$nextTick(() => {
				this.$refs.contractDiaRef.reset();
			});
		},
		// 生成合同对话框取消按钮
		cancelContract() {
			this.openContract = false;
			this.$refs.contractDiaRef.reset();
			this.getList();
		},
		//查看历史合同
		openHistoryContract(row) {
			this.openHistoryContractVis = true;
			this.$nextTick(() => {
				this.$refs.historyContractRef.getHistoryContract(row.customId);
			})
		},
		// 图片下载
		downLoadImg() {
			let fileName = '';
			let key = this.downLoadImgObj.key;
			let allItem = this.downLoadImgObj.row.contractItem;
			let itemArray = allItem.split(";");
			for (let i = 0; i < itemArray.length; i++) {
				if (itemArray[i].split(',')[0] == key) {
					fileName = itemArray[i].split(',')[1];
					break
				}
			}
			this.$download.downloadFile('/common/downloadFile', fileName, false, false, fileName);
		},
	},
};
</script>

<style scoped>
.el-row {
	margin-bottom: 20px;
}

.newTree /deep/ .el-tree-node__content {
	height: 40px !important;
}

.newdialog .el-row {
	margin-bottom: 0px !important;
}

.width18 {
	width: 180px;
}

.upload-demo /deep/ .el-upload {
	width: 100% !important;
}
</style>